package com.web;

import com.module.Product;
import com.service.ProductService;
import com.service.impl.ProductServiceImpl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Scanner;

public class WebProduct {

    public static void main(String[] args) {

   try {
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
       // Scanner scanner=new Scanner(System.in);
        System.out.println("C:新增，U：修改，D：删除，I：查询，FA：查询所有，DA：删除所有,Q:退出");

        String scan = bufferedReader.readLine();
        // String scan = scanner.nextLine();

        switch(scan.toUpperCase()){
            case "C":
                System.out.println("新增");
                break;
            case "U":
                System.out.println("修改");
                break;
            case "D":
                System.out.println("删除");
                break;
            case "I":
            //  System.out.println("查询");
                findProductByPid();
                break;
            case "FA":
            //  System.out.println("查询所有");

                findAllProduct();
                break;
            case "DA":
                System.out.println("删除所有");
                break;
            case "Q":
                System.out.println("退出");
                System.exit(1);
                 break;
            default:
                System.out.println("你输入有误");
        }
      } catch (Exception e) {
       System.out.println("系统正在维护,清稍后重试");
       e.printStackTrace();
     }
    }
  //  查询所有
   public static void findAllProduct(){
       ProductService productService=new ProductServiceImpl();
       List<Product> allProduct = productService.findAllProduct();
       System.out.println(allProduct);
   }

  //  查询
   public static void findProductByPid(){
      try{
          ProductService productService=new ProductServiceImpl();
          BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
          String s = bufferedReader.readLine();
          int pid = Integer.parseInt(s);
          Product productByPid = productService.findProductByPid(pid);
          System.out.println(productByPid);
      }catch(Exception e){
          e.printStackTrace();
          System.out.println("系统正在维护,清稍后重试");
      }

   }
}
